package com.rhyton.component.upload.service.imp;

import java.util.List;

import org.springframework.dao.DataAccessException;

import com.rhyton.component.upload.dao.AttactFileInfoDao;
import com.rhyton.component.upload.dao.UpDownloadFileDao;
import com.rhyton.component.upload.domain.AttactFile;
import com.rhyton.component.upload.service.AttactFileManager;

public class AttactFileManagerImp implements AttactFileManager {
    private AttactFileInfoDao attactFileInfoDao;

    private UpDownloadFileDao upDownloadFileDao;

    public AttactFile getAttachFile(Long fileId) {
	AttactFile attactFile = this.attactFileInfoDao.get(fileId);//得到附件信息
	if (attactFile != null) {
	    attactFile.setFile(this.upDownloadFileDao.getFile(attactFile));//得到实际文件
	}
	return attactFile;
    }
    
    
    public void delete(Long fileId) throws DataAccessException {
	AttactFile attactFile = this.attactFileInfoDao.get(fileId);
	this.upDownloadFileDao.deleteFile(attactFile);// 删除附件文件
	this.attactFileInfoDao.remove(fileId);// 删除附件文件相关信息
    }

    public void delete(List<Long> ids) throws DataAccessException {
	for (Long id : ids) {
	    delete(id);
	}
    }

    public void upload(AttactFile af) throws DataAccessException {
	this.upDownloadFileDao.upload(af);// 保存真实附件
	this.attactFileInfoDao.save(af);// 在数据库中记录文件相关信息
    }


    public List<AttactFile> queryAttactFiles(AttactFile attactFile) throws DataAccessException {
	return this.attactFileInfoDao.queryByExample(attactFile);
    }
    //=================================The Setter/Getter Methods==========================//
    public AttactFileInfoDao getAttactFileInfoDao() {
	return attactFileInfoDao;
    }

    public void setAttactFileInfoDao(AttactFileInfoDao attactFileDao) {
	this.attactFileInfoDao = attactFileDao;
    }

    public UpDownloadFileDao getUpDownloadFileDao() {
	return upDownloadFileDao;
    }

    public void setUpDownloadFileDao(UpDownloadFileDao upDownloadFileDao) {
	this.upDownloadFileDao = upDownloadFileDao;
    }



}
